#!/usr/bin/node

const log = console.log,
      fs = require('fs'),
      http = require('http');

http.createServer((req,res)=>{
  log(`${req.method} ${req.url} http/${req.httpVersion}`);

  log('header:',req.headers);
  log(`process pid:${process.pid}`);

  let fileName = __dirname + req.url;
  fs.readFile(fileName,(err,data)=>{
    if(err){
      console.error(err.message);
      res.statusCode = 404;
      res.end(err.message);
      process.exit(1);
    }
    res.end(data);
  });
  
  log(`process.memoryUsage().heapUsed:${process.memoryUsage().heapUsed}`);

}).listen(8080);


